package com.macro.mall.portal.controller;

import com.macro.mall.common.api.CommonPage;
import com.macro.mall.common.api.CommonResult;
import com.macro.mall.model.BmsVolunteerRegistration;
import com.macro.mall.portal.dto.BmsVolunteerRegistrationParam;
import com.macro.mall.portal.service.BmsRecruitmentInformationService;
import com.macro.mall.portal.service.BmsVolunteerRegistrationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * 志愿者报名ontroller
 * Created by macro on 2018/4/26.
 */
@Controller
@Api(tags = "BmsVolunteerRegistrationController")
@Tag(name = "BmsVolunteerRegistrationController", description = "志愿者报名管理")
@RequestMapping("/volunteerMp")
public class BmsVolunteerRegistrationController {
    @Autowired
    private BmsVolunteerRegistrationService bmsVolunteerRegistrationService;

    /**
     * 传token+招募信息id
     * @param bmsVolunteerRegistration
     * @return
     */
    @ApiOperation("添加招募信息报名")
    @RequestMapping(value = "/create", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult<?> create(@RequestBody BmsVolunteerRegistration bmsVolunteerRegistration) {
        try{
            int count = bmsVolunteerRegistrationService.create(bmsVolunteerRegistration);
            return CommonResult.success("报名成功！");
        }catch (Exception e){
            return CommonResult.failed("报名失败！");
        }
    }

    @ApiOperation("取消招募信息报名")
    @RequestMapping(value = "/update", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult<?> update(@RequestBody BmsVolunteerRegistration bmsVolunteerRegistration) {
        int count = bmsVolunteerRegistrationService.update(bmsVolunteerRegistration);
        if (count > 0) {
            return CommonResult.success(count);
        } else {
            return CommonResult.failed();
        }
    }

    @ApiOperation("查询当前会员的招募信息列表")
    @RequestMapping(value = "/getListByUserId", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult<?> getListByUserId(@RequestBody BmsVolunteerRegistration bmsVolunteerRegistration) {
        List<BmsVolunteerRegistration> result = bmsVolunteerRegistrationService.getListByUserId(bmsVolunteerRegistration);
        return CommonResult.success(result);
    }


}
